<html>
<head><meta charset="utf-8"><title>rust-analyzer lambda inference · t-compiler/rust-analyzer · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/index.html">t-compiler/rust-analyzer</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/rust-analyzer.20lambda.20inference.html">rust-analyzer lambda inference</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="197783564"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/rust-analyzer%20lambda%20inference/near/197783564" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Roland Kuhn <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/rust-analyzer.20lambda.20inference.html#197783564">(May 16 2020 at 08:11)</a>:</h4>
<p>I really like rust-analyzer, it is fast and displays very helpful inline information. One area where it fails me (on nightly) is when using named functions in lambda positions, or when using a pattern in the argument list of a lambda — in those cases, the result type is <code>{unknown}</code>. Is there a ticket for this already or am I doing something unusual? (casual search didn’t reveal one, but there are so many tickets … )</p>
<div class="codehilite"><pre><span></span><code><span class="n">stream</span><span class="w"></span>
<span class="w">    </span><span class="p">.</span><span class="n">map</span><span class="p">(</span><span class="n">my_function</span><span class="p">)</span><span class="w"> </span><span class="c1">// this trips it up</span>
<span class="w">    </span><span class="p">.</span><span class="n">map</span><span class="p">(</span><span class="o">|</span><span class="n">x</span><span class="p">,</span><span class="w"> </span><span class="p">(</span><span class="n">a</span><span class="p">,</span><span class="w"> </span><span class="n">b</span><span class="p">)</span><span class="o">|</span><span class="w"> </span><span class="o">..</span><span class="p">.</span><span class="w"> </span><span class="p">)</span><span class="w"> </span><span class="c1">// this also</span>
</code></pre></div>



<a name="197783743"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/rust-analyzer%20lambda%20inference/near/197783743" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/rust-analyzer.20lambda.20inference.html#197783743">(May 16 2020 at 08:17)</a>:</h4>
<p><a href="https://github.com/rust-analyzer/rust-analyzer/issues/4281">https://github.com/rust-analyzer/rust-analyzer/issues/4281</a></p>



<a name="197783744"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/rust-analyzer%20lambda%20inference/near/197783744" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/rust-analyzer.20lambda.20inference.html#197783744">(May 16 2020 at 08:17)</a>:</h4>
<p>probably this</p>



<a name="197783875"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/rust-analyzer%20lambda%20inference/near/197783875" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Roland Kuhn <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/rust-analyzer.20lambda.20inference.html#197783875">(May 16 2020 at 08:20)</a>:</h4>
<p>Ah, right, that definitely looks like what I observed in the first case. Does it also cover the second or shall I open another issue?</p>



<a name="197784005"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/rust-analyzer%20lambda%20inference/near/197784005" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/rust-analyzer.20lambda.20inference.html#197784005">(May 16 2020 at 08:24)</a>:</h4>
<p>I think the second is tripped up because of the first one?</p>



<a name="197784015"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/rust-analyzer%20lambda%20inference/near/197784015" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/rust-analyzer.20lambda.20inference.html#197784015">(May 16 2020 at 08:24)</a>:</h4>
<p>oh, actually, let me check for patterns</p>



<a name="197784036"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/rust-analyzer%20lambda%20inference/near/197784036" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Roland Kuhn <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/rust-analyzer.20lambda.20inference.html#197784036">(May 16 2020 at 08:25)</a>:</h4>
<p>ah, no, it happens independently, I only wrote that up as a strawman</p>



<a name="197784041"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/rust-analyzer%20lambda%20inference/near/197784041" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/rust-analyzer.20lambda.20inference.html#197784041">(May 16 2020 at 08:25)</a>:</h4>
<p>right, patterns do trip type inference up as well, I don't think we have an issue for that, if you  create one with a minimal reproducible example (ideally, without using <code>std</code>), that would be helpful!</p>



<a name="197784042"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/rust-analyzer%20lambda%20inference/near/197784042" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/rust-analyzer.20lambda.20inference.html#197784042">(May 16 2020 at 08:25)</a>:</h4>
<p>(there's also a chance that the issue already exist, but I don't recall one)</p>



<a name="197784087"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/rust-analyzer%20lambda%20inference/near/197784087" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Roland Kuhn <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/rust-analyzer.20lambda.20inference.html#197784087">(May 16 2020 at 08:26)</a>:</h4>
<p>okay, will try to minimize (of course this happens in our 30'000 LOC source, as always ;-) )</p>



<a name="197784171"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/rust-analyzer%20lambda%20inference/near/197784171" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/rust-analyzer.20lambda.20inference.html#197784171">(May 16 2020 at 08:29)</a>:</h4>
<p>Another useful "small" yak-shave is implementing test-case minimizer :D</p>



<a name="197784384"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/rust-analyzer%20lambda%20inference/near/197784384" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Roland Kuhn <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/rust-analyzer.20lambda.20inference.html#197784384">(May 16 2020 at 08:35)</a>:</h4>
<p>I got it, submitting issue …</p>



<a name="197784600"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/rust-analyzer%20lambda%20inference/near/197784600" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Roland Kuhn <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/rust-analyzer.20lambda.20inference.html#197784600">(May 16 2020 at 08:40)</a>:</h4>
<p><a href="https://github.com/rust-analyzer/rust-analyzer/issues/4476">https://github.com/rust-analyzer/rust-analyzer/issues/4476</a></p>



<a name="197784634"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/rust-analyzer%20lambda%20inference/near/197784634" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Roland Kuhn <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/rust-analyzer.20lambda.20inference.html#197784634">(May 16 2020 at 08:40)</a>:</h4>
<p>so it only happens when the closure takes arguments by reference</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>